/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_kernel.htm
 *
 * Zhiqim Kernel is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.kernel.model.results;

/**
 * 无值[错误码/错误信息]结果对象，用于替换boolean型返回可能的[错误码/错误信息]
 *
 * @version v1.0.0 @author zgzou 2021年11月23日 新建与整理
 */
public class R4
{
    private static final R4 C = new R4();

    private int errCode;
    private String errMsg;
    
    /** 是否成功 */
    public boolean success()
    {
        return errCode == 0;
    }

    /** 是否失败 */
    public boolean failure()
    {
        return !success();
    }
    
    /************************************************************************/
    //静态方法创建对象
    /************************************************************************/
    
    /** 静态方法创建对象并初始化正确值 */
    public static R4 correct()
    {
        return C;
    }
    
    /** 静态方法创建对象并初始化错误码&错误信息 */
    public static R4 error(int errCode, String errMsg)
    {
        R4 r = new R4();
        r.errCode = errCode;
        r.errMsg = errMsg;
        return r;
    }
    
    /************************************************************************/
    //获取值
    /************************************************************************/
    
    public int errCode()
    {
        return errCode;
    }
    
    public String errMsg()
    {
        return errMsg;
    }
    
    public String errMsg(int len)
    {
        return errMsg==null?null:(errMsg.length()>len?errMsg.substring(0, len):errMsg);
    }
}
